/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ReconocerDlg.java
 *
 * Created on 18/05/2009, 22:08:02
 */
package bender;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;

/**
 *
 * @author Ramiro
 */
public class ReconocerDlg extends javax.swing.JDialog {

    /** Creates new form ReconocerDlg */
    public ReconocerDlg(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtArchivo = new javax.swing.JTextField();
        btnAgregarArchivo = new javax.swing.JButton();
        btnReconocer = new javax.swing.JButton();
        btnCerrar = new javax.swing.JButton();
        txtStatus = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(bender.BenderApp.class).getContext().getResourceMap(ReconocerDlg.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        txtArchivo.setEditable(false);
        txtArchivo.setText(resourceMap.getString("txtArchivo.text")); // NOI18N
        txtArchivo.setName("txtArchivo"); // NOI18N

        btnAgregarArchivo.setText(resourceMap.getString("btnAgregarArchivo.text")); // NOI18N
        btnAgregarArchivo.setName("btnAgregarArchivo"); // NOI18N
        btnAgregarArchivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarArchivoActionPerformed(evt);
            }
        });

        btnReconocer.setText(resourceMap.getString("btnReconocer.text")); // NOI18N
        btnReconocer.setName("btnReconocer"); // NOI18N
        btnReconocer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReconocerActionPerformed(evt);
            }
        });

        btnCerrar.setText(resourceMap.getString("btnCerrar.text")); // NOI18N
        btnCerrar.setName("btnCerrar"); // NOI18N
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        txtStatus.setEditable(false);
        txtStatus.setText(resourceMap.getString("txtStatus.text")); // NOI18N
        txtStatus.setName("txtStatus"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(txtArchivo, javax.swing.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAgregarArchivo, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnReconocer)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCerrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtArchivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAgregarArchivo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnReconocer)
                    .addComponent(btnCerrar)
                    .addComponent(txtStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.dispose();
}//GEN-LAST:event_btnCerrarActionPerformed

    private void btnAgregarArchivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarArchivoActionPerformed


        int returnVal = fc.showOpenDialog(this.btnAgregarArchivo);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File archivo = fc.getSelectedFile();
            txtArchivo.setText(archivo.getAbsolutePath());
            fc = new JFileChooser(archivo.getParent());
        }
}//GEN-LAST:event_btnAgregarArchivoActionPerformed

    private void btnReconocerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReconocerActionPerformed
        try {
            txtStatus.setText(new Integer(BenderApp.getApplication().getRed().reconocer(txtArchivo.getText())).toString());
        } catch (IOException ex) {
            txtStatus.setText(ex.toString());
        }
    }//GEN-LAST:event_btnReconocerActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                ReconocerDlg dialog = new ReconocerDlg(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregarArchivo;
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnReconocer;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField txtArchivo;
    private javax.swing.JTextField txtStatus;
    // End of variables declaration//GEN-END:variables
    private JFileChooser fc = new JFileChooser();
}

